package com.chuji.crmcj.act;

import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ExpandableListView;
import android.widget.LinearLayout;
import android.widget.ListView;

import com.alibaba.fastjson.JSON;
import com.android.volley.Response;
import com.chuji.crmcj.R;
import com.chuji.crmcj.adapter.InsureHisUserAda;
import com.chuji.crmcj.bean.InsUseHisInfo;
import com.chuji.crmcj.utils.SPUtils;
import com.chuji.crmcj.utils.UIUtils;
import com.chuji.crmcj.utils.UrlUtils;

import java.util.ArrayList;

/**
 * Created by w.pitt on 2016/2/3.
 */
public class InsureHistoryUseAct extends BaseActivity implements AdapterView.OnItemClickListener, View.OnClickListener {

    private ExpandableListView mLvHistory;
    private String salerID;
    private InsUseHisInfo insUseHisInfo;
    private LinearLayout mll_content;
    private ListView mLvInsureHis;

    @Override
    protected void initView() {
        setContentView(R.layout.act_history_use);
        mLvInsureHis = (ListView) findViewById(R.id.lv_insure_his);
        mLvHistory = (ExpandableListView) findViewById(R.id.lv_history);
//        mll_content = (LinearLayout) findViewById(R.id.ll_content);
    }

    private ArrayList<String> mData = new ArrayList<String>();

    @Override
    protected void initData() {
        mTvBarTitle.setText("历史用户");

        salerID = SPUtils.getString(UIUtils.getContext(), "UserID", "");

        reqNetData();
    }

    private void reqNetData() {
        //请求 组数据
//        reqGroupData();
        InsureHisUserAda insureHisUserAda = new InsureHisUserAda(InsureHistoryUseAct.this, insUseHisInfo, mLvInsureHis);
        mLvInsureHis.setAdapter(insureHisUserAda);
        //请求 贷款详情
//        reqChildData();
    }

    private void reqGroupData() {
        String strURL = String.format(UrlUtils.GetInsuranceRecordForUserHistory + "&SalesID=%s&PageSize=10&PageIndex=1", salerID);
        volleyRequest(strURL, new Response.Listener<String>() {
            @Override
            public void onResponse(String s) {
                insUseHisInfo = JSON.parseObject(s, InsUseHisInfo.class);
                UIUtils.runInMainThread(new Runnable() {
                    @Override
                    public void run() {
                        if (insUseHisInfo.getCount() != 0) {
//                            InsureHisUserAda insureHisUserAda = new InsureHisUserAda(InsureHistoryUseAct.this, insUseHisInfo, mLvInsureHis);
//                            mLvInsureHis.setAdapter(insureHisUserAda);

//                            InsureHistoryAdapter adapter = new InsureHistoryAdapter(this, insUseHisInfo, mLvHistory);
//                            mLvHistory.setAdapter(adapter);
                        }
                    }
                });
            }
        });
    }

    @Override
    protected void initListener() {
        mBtnBarLeftArr.setOnClickListener(this);
//        mLvHistory.setOnItemClickListener(this);
    }

    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
        UIUtils.startActivity(new Intent(this, ClientDetailAct.class));
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_left_arr:
                finish();
                break;
        }
    }
}
